#!/bin/bash

git pull
go build -gcflags="-l" -o api_smart_home main.go

#chmod +x api_smart_home
mv api_smart_home /home/www/smart_home/api/api_smart_home
cp -r ./conf /home/www/smart_home/api
cp -r ../conf /home/www/smart_home

#pid=`ps -ef|grep /home/www/smart_home/api/api_smart_home | grep -v "grep" | awk '{print $2}'`
#if [ $pid != "" ]
#then
#    kill $pid
#end

supervisorctl stop api_smart_home

for pid in $(ps -ef | grep /home/www/smart_home/api/api_smart_home | grep -v grep | cut -c 15-20); do
    echo $pid
    kill -9 $pid
done

supervisorctl start api_smart_home
tail -f /usr/local/supervisor/logs/api_smart_home.log